package com.github.sd4324530.fastweixin.api.extra;

import com.github.sd4324530.fastweixin.api.config.ApiConfig;

/**
 * 扩展的一个ApiConfig
 */
public class ExtraApiConfig implements ApiConfig {

    private final String appid;
    private final String secret;

    private final TokenCache cache;

    public ExtraApiConfig(String appid, String secret, TokenCache cache) {
        this.appid = appid;
        this.secret = secret;
        this.cache = cache;

        cache.addConfig(this);
    }

    @Override
    public String getAccessToken() {
        Token token = cache.get(appid, TokenType.ACCESS_TOKEN);
        return token.getToken();
    }

    @Override
    public String getJsApiTicket() {
        Token token = cache.get(appid,TokenType.JSAPI_TICKET);
        return token.getToken();
    }

    @Override
    public String getSecret() {
        return secret;
    }

    @Override
    public String getAppid() {
        return appid;
    }
}
